$(function(){
    $("body").delegate("._follow","click",function(){
        if(!_is_login()){return;};
        var _self=$(this),_fan=_self.attr("data-val"),_author_id=_self.parents("li").attr("data-uid");
        if(is_login.uuid == _author_id){$.mvalidateTip("不能关注自己哦");return;}
        _fan=1-_fan;
        doRequest("/ajax/cancel_fan_act",{author_id:_author_id,is_fan:_fan},true,function(data){
            _self.attr("data-val",_fan);
            if(_fan==1){
                $.mvalidateTip("已关注");
                _self.removeClass("icon_unfollow").addClass("icon-followed").html("&#xe691;");
            }else{
                $.mvalidateTip("已取消关注");
                _self.removeClass("icon-followed").addClass("icon_unfollow").html("&#xe6b6;");
            }
        },function(data){$.mvalidateTip(data.errorMsg);});
    });
    $.fn.sex_selector = function(){
        var _self = $(this),
            _box = $(".sex-box"),
            _i = _self.find("i"),
            _content_box = $(".sex-content-box"),
            _li = _box.find("li"),
            _close = _box.find("._close");
        var S = function(){
            _box.stop().fadeIn();
            _content_box.stop().animate({bottom:'15px'},300);
            return;
        }
        var F = function(){
            _box.stop().fadeOut();
            _content_box.stop().animate({bottom:'-50px'},200);
            return;
        }
        
        _close.on("click",function(){
            return F();
        });
        _box.on("click",function(){
            return F();
        });
        _li.on("click",function(e){
            var _this = $(this),
                _type = _this.attr("data-type");
            if(!_is_login()){return;}
            if(_type == 0){return;}
            
            doRequest("/ajax/ajax_modify_baseinfo",{setValue:_type,setType:"sex"},true,function(data){
                _i.text(_type == 1 ? "男" : "女");
                $.mvalidateTip("已保存");
                return F();
            },function(data){
                $.mvalidateTip(data.errorMsg);
            });
            e.stopPropagation();
        });
        return S();
    }
    $(".modify-sex-btn").on("click",function(){
        return $(this).sex_selector();
    });
    $.fn.photo_selector = function(){
        var _self = $(this),
            _box = $(".photo-box"),
            _i = _self.find("i"),
            _content_box = $(".photo-content-box"),
            _li = _box.find("li"),
            _close = _box.find("._close");
        var S = function(){
            _box.stop().fadeIn();
            _content_box.stop().animate({bottom:'15px'},10);
            return;
        }
        var F = function(){
            _box.stop().fadeOut();
            _content_box.stop().animate({bottom:'-50px'},10);
            return;
        }
        
        _close.on("click",function(){
            return F();
        });
        _box.on("click",function(){
            return F();
        });
        return S();
    }
    $(".modify-headimg-btn").on("click",function(){
        return $(this).photo_selector();
    });
    $(".follow-act").on("click",function(){
        if(!_is_login()){return;};
        var _self=$(this),_fan=_self.attr("data-val");
        if(is_login.uuid == uuid){$.mvalidateTip("不能关注自己哦");return;}
        _fan=1-_fan;
        doRequest("/ajax/cancel_fan_act",{author_id:uuid,is_fan:_fan},true,function(data){
            _self.attr("data-val",_fan);
            if(_fan==1){
                $.mvalidateTip("已关注");
                _self.addClass("col-red").find("i").text('已关注');
            }else{
                $.mvalidateTip("已取消关注");
                _self.removeClass("col-red").find("i").text('关注');
            }
        },function(data){$.mvalidateTip(data.errorMsg);});
    });
    
     //分享窗口
    $.fn.share = function(flag){
        var _share_box = $(".share-box"),_ainfo = $("#_ainfo"),
            _content_box = _share_box.find(".share-content-box"),
            _lis = _share_box.find("li"),
            _close = _share_box.find("._close");
        var S = function(){
            _share_box.stop().fadeIn();
            _content_box.animate({'bottom':'0px'},500);
        }
        var F = function(){//移除分享框
            _share_box.stop().fadeOut();
            _content_box.stop().animate({'bottom':'-200px'},500);
        }
        _share_box.one("click",function(){
            return F();//阴影处移除
        });
        _close.on("click",function(){
            return F();
        });
        _content_box.on("click",function(e){
            e.stopPropagation();
        });
        _lis.css("width","50%");
        if(flag){
            _lis.unbind("click").on("click",function(){
                var _li = $(this),_type = _li.attr("data-type");
                var _title = _ainfo.attr("data-title"),_desc = _ainfo.attr("data-desc"),_link = _ainfo.attr("data-link"),_thumb = _ainfo.attr("data-thumb");
                var from = "（分享自@弹溜溜-杭州乌云网络）";
                var z = encodeURIComponent(_title),s = "",u = encodeURIComponent(_link),img = _thumb;
                var r = encodeURIComponent("--弹溜溜，儿时快乐的指尖回忆。在这里发现更多志趣相投的伙伴；参与最前沿的互联网金融体验；探索最酷最好玩的生活..." + (_type == "sina" ? from : "")) ;
                switch(_type){
                    case "sina"://微博
                        e = "http://service.weibo.com/share/share.php?url={0}&title="+ z + s + r +"&pic={1}", n = String.Format(e, u ,img);
                    break;
                    case "qq-space"://qq空间
                        e = "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={0}&title=" + z + "&desc={1}&summary={1}", n = String.Format(e, u, (z + r));
                    break;
                }
                try {
                    window.open(n);
                } catch (u) {
                    window.open(n, t);
                }
                return;
            });
        }
        return S();
    }
    //分享提示
    $.fn.share_msg = function(){
        var _self = $(this);
        _self.on("click",function(){
            return _self.hide();
        });
        return _self.show();
    }
    //分享相关
    $("._share").on("click",function(){
        var brower = brower_info(),_sinfo = $("#_ainfo");
        var _link = _sinfo.attr("data-link"),_title = _sinfo.attr("data-title"),_desc = _sinfo.attr("data-desc"),_thumb = _sinfo.attr("data-thumb");
        if(brower.is_weixin()){
            return $("#wx-share").share_msg();
        }else if(brower.is_ucBrower() || brower.is_qqBrower()){
            return $(this).share(),new native_share("share-box",{url:_link,title:_title,desc:_desc,img:_thumb,img_title:_title,from:"弹溜溜"});
        }else{
            return $(this).share(true); 
        }
    });
});
function AnalyticEmotion(s) {
    if(typeof (s) != "undefined") {
        var sArr = s.match(/\[.*?\]/g);
        if(sArr != "" && sArr != null){
            for(var i = 0; i < sArr.length; i++){
                if(uSinaEmotionsHt.containsKey(sArr[i])) {
                    var reStr = "<img src=\"" + uSinaEmotionsHt.get(sArr[i]) + "\" height=\"22\" width=\"22\" />";
                    s = s.replace(sArr[i], reStr);
                }
            }
        }
    }
    return s;
}



